package cn.com.surker.system.controller;

import cn.com.surker.common.AbstractController;
import cn.com.surker.material.entity.MainMaterialWeight;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.entity.DataSourceInfo;
import cn.com.surker.system.service.HomeService;
import cn.com.surker.util.DateUtil;
import cn.com.surker.util.ReportDateUtils;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author lucky
 * @create 2025年01月23 21:43
 * @desc
 */
@RestController("erp_home")
@RequestMapping("/home")
public class HomeController extends AbstractController {

    @Resource
    private HomeService homeService;

    /**
     * 加载过磅车辆信息
     * @return
     */
    @RequestMapping(value = "/load-weight", method = RequestMethod.POST)
    public RestResultDto loadWeightCar(Integer type){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<MainMaterialWeight> weightList = homeService.loadWeightCar(startTime, endTime, type);
            if (weightList == null || weightList.size() == 0)
                return RestResultDto.fail("没有任何过磅数据");
            return RestResultDto.success(weightList);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }

    /**
     * 加载标题信息
     * @return
     */
    @RequestMapping(value = "/load-title", method = RequestMethod.POST)
    public RestResultDto loadTitleVal(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            Map<String, Object> map = homeService.loadTitleVal(startTime, endTime);
            return RestResultDto.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }

    /**
     * 加载图标信息
     * @return
     */
    @RequestMapping(value = "/load-trend", method = RequestMethod.POST)
    public RestResultDto loadProTrend(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<Map<String, Object>> list = homeService.loadProTrend(startTime, endTime);
            if (list == null || list.size() == 0)
                return RestResultDto.fail("没有任何数据");
            return RestResultDto.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }
    /**
     * 加载生产线top信息
     * @return
     */
    @RequestMapping(value = "/load-line", method = RequestMethod.POST)
    public RestResultDto loadLineTop(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<Map<String, Object>> list = homeService.loadLineTop(startTime, endTime);
            if (list == null || list.size() == 0)
                return RestResultDto.fail("没有任何数据");
            return RestResultDto.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }
    /**
     * 加载车辆top信息
     * @return
     */
    @RequestMapping(value = "/load-car", method = RequestMethod.POST)
    public RestResultDto loadCarTop(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<Map<String, Object>> list = homeService.loadCarTop(startTime, endTime);
            if (list == null || list.size() == 0)
                return RestResultDto.fail("没有任何数据");
            return RestResultDto.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }
    public static void main(String[] args){
        System.out.println(ReportDateUtils.getToday());
    }
    /**
     * 加载合同进度信息
     * @return
     */
    @RequestMapping(value = "/load-con-progress", method = RequestMethod.POST)
    public RestResultDto loadConProgress(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<Map<String, Object>> list = homeService.loadConProgress(startTime, endTime);
            if (list == null || list.size() == 0)
                return RestResultDto.fail("没有任何数据");
            return RestResultDto.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }
    /**
     * 加载强度占比信息
     * @return
     */
    @RequestMapping(value = "/load-strength", method = RequestMethod.POST)
    public RestResultDto loadStrengthProportion(){
        try {
            String startTime = "";
            String endTime = "";
            Date nowDate = new Date();
            if (StringUtils.isNull(startTime)) {
                startTime = ReportDateUtils.getToday() + " 08:30:00";
            }
            if (StringUtils.isNull(endTime)) {
                endTime = DateUtil.convertString(nowDate);
            }
//            startTime = "2025-01-01 08:30:00";
            List<Map<String, Object>> list = homeService.loadStrengthProportion(startTime, endTime);
            if (list == null || list.size() == 0)
                return RestResultDto.fail("没有任何数据");
            return RestResultDto.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResultDto.fail("系统异常,数据加载失败");
        }
    }
}
